package com.ruoyi.youtian.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.youtian.domain.FaultNotifyAnnounce;
import com.ruoyi.youtian.service.IFaultNotifyAnnounceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报警消息通告Controller
 * 
 * @author ruoyi
 * @date 2022-12-08
 */
@Controller
@RequestMapping("/youtian/announce")
public class FaultNotifyAnnounceController extends BaseController
{
    private String prefix = "youtian/announce";

    @Autowired
    private IFaultNotifyAnnounceService faultNotifyAnnounceService;

    @RequiresPermissions("youtian:announce:view")
    @GetMapping()
    public String announce()
    {
        return prefix + "/announce";
    }

    /**
     * 查询报警消息通告列表
     */
    @RequiresPermissions("youtian:announce:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FaultNotifyAnnounce faultNotifyAnnounce)
    {
        startPage();
        List<FaultNotifyAnnounce> list = faultNotifyAnnounceService.selectFaultNotifyAnnounceList(faultNotifyAnnounce);
        return getDataTable(list);
    }

    /**
     * 导出报警消息通告列表
     */
    @RequiresPermissions("youtian:announce:export")
    @Log(title = "报警消息通告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FaultNotifyAnnounce faultNotifyAnnounce)
    {
        List<FaultNotifyAnnounce> list = faultNotifyAnnounceService.selectFaultNotifyAnnounceList(faultNotifyAnnounce);
        ExcelUtil<FaultNotifyAnnounce> util = new ExcelUtil<FaultNotifyAnnounce>(FaultNotifyAnnounce.class);
        return util.exportExcel(list, "报警消息通告数据");
    }

    /**
     * 新增报警消息通告
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报警消息通告
     */
    @RequiresPermissions("youtian:announce:add")
    @Log(title = "报警消息通告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FaultNotifyAnnounce faultNotifyAnnounce)
    {
        return toAjax(faultNotifyAnnounceService.insertFaultNotifyAnnounce(faultNotifyAnnounce));
    }

    /**
     * 修改报警消息通告
     */
    @RequiresPermissions("youtian:announce:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FaultNotifyAnnounce faultNotifyAnnounce = faultNotifyAnnounceService.selectFaultNotifyAnnounceById(id);
        mmap.put("faultNotifyAnnounce", faultNotifyAnnounce);
        return prefix + "/edit";
    }

    /**
     * 修改保存报警消息通告
     */
    @RequiresPermissions("youtian:announce:edit")
    @Log(title = "报警消息通告", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FaultNotifyAnnounce faultNotifyAnnounce)
    {
        return toAjax(faultNotifyAnnounceService.updateFaultNotifyAnnounce(faultNotifyAnnounce));
    }

    /**
     * 删除报警消息通告
     */
    @RequiresPermissions("youtian:announce:remove")
    @Log(title = "报警消息通告", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(faultNotifyAnnounceService.deleteFaultNotifyAnnounceByIds(ids));
    }
}
